home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Software Contest 3 / FM Towns Software Contest 3.iso / exp / astral / a1 / game / source / test.c < prev    next >
C/C++ Source or Header  |  1994-01-07  |  4KB  |  198 lines

  1. // "test.c"
  2. // サンプルプログラム
  3.  
  4. #define MAIN
  5. #include <stdio.h>
  6. #include <egb.h>
  7. #include <snd.h>
  8. #include <spr.h>
  9. #include "wire3d.h"
  10. #include "sin8.c"
  11.  
  12. #define NON_INT
  13.  
  14. // マクロ設定
  15.  
  16. #define JOY_UP(A)     if((A&0x01)==0)
  17. #define JOY_DOWN(A)   if((A&0x02)==0)
  18. #define JOY_LEFT(A)   if((A&0x04)==0)
  19. #define JOY_RIGHT(A)  if((A&0x08)==0)
  20. #define JOY_TRIG_A(A) if((A&0x10)==0)
  21. #define JOY_TRIG_B(A) if((A&0x20)==0)
  22. #define JOY_SELECT(A) if((A&0x03)==0)
  23. #define JOY_RUN(A)    if((A&0x0c)==0)
  24.  
  25. // グローバル変数設定
  26.  
  27. char Gwork[1536];
  28.  
  29. SCREEN_LOCATE Screen[MAX_OBJECT];
  30.  
  31. int W_page=0,D_page=1,Draw_end=2,End_code=0,W;
  32.  
  33. ANGLE Angle[3]={0,0,0},Angle_w[3]={0,0,0};
  34. int Offset[3]={0,0,0},Offset1[3]={0,0,0};
  35.  
  36. int Step;
  37.  
  38. #define OBJ_NUM 1
  39.  
  40. WIRE_SPACE Space[OBJ_NUM]={
  41.     { 0,{  0,  0,  0},{    0,     0,  1000}},
  42. };
  43.  
  44. int H_i;
  45. int H_offset2[3];
  46.  
  47. // 関数
  48.  
  49. void VSYNC_handler(void)
  50. {
  51.     if(Draw_end==1){
  52.         W=D_page;D_page=W_page;W_page=W;
  53.         chgpage(D_page);
  54.         Draw_end=2;
  55.     }
  56.     /*
  57.     Angle[1]-=Step;
  58.     return;
  59.     */
  60.     
  61.     H_i=pad_in();
  62.     JOY_RUN(H_i){
  63.         End_code=1;
  64.     }
  65.     JOY_SELECT(H_i){
  66.         End_code=1;
  67.     }
  68.     JOY_UP(H_i){
  69.         Angle_w[0]-=Step;
  70.     }
  71.     JOY_DOWN(H_i){
  72.         Angle_w[0]+=Step;
  73.     }
  74.     JOY_LEFT(H_i){
  75.         Angle_w[1]+=Step;
  76.     }
  77.     JOY_RIGHT(H_i){
  78.         Angle_w[1]-=Step;
  79.     }
  80.     
  81.     JOY_TRIG_A(H_i){
  82.         H_offset2[1]=( (Step*20)*sin_data[Angle[0]]);
  83.         H_offset2[2]=( (Step*20)*cos_data[Angle[0]])>>7;
  84.         H_offset2[0]=(-H_offset2[2] * sin_data[Angle[1]]);
  85.         H_offset2[2]=( H_offset2[2] * cos_data[Angle[1]]);
  86.         
  87.         Offset1[0]+=H_offset2[0];
  88.         Offset1[1]+=H_offset2[1];
  89.         Offset1[2]+=H_offset2[2];
  90.     }
  91.     JOY_TRIG_B(H_i){
  92.         H_offset2[1]=( (Step*40)*sin_data[Angle[0]]);
  93.         H_offset2[2]=( (Step*40)*cos_data[Angle[0]])>>7;
  94.         H_offset2[0]=(-H_offset2[2] * sin_data[Angle[1]]);
  95.         H_offset2[2]=( H_offset2[2] * cos_data[Angle[1]]);
  96.         
  97.         Offset1[0]-=H_offset2[0];
  98.         Offset1[1]-=H_offset2[1];
  99.         Offset1[2]-=H_offset2[2];
  100.     }
  101.     
  102.     #ifndef NON_INT
  103.         if(Draw_end==2){
  104.     #endif
  105.             Angle[0]=Angle_w[0];
  106.             Angle[1]=Angle_w[1];
  107.             Angle[2]=Angle_w[2];
  108.             Offset[0]=Offset1[0]>>7;
  109.             Offset[1]=Offset1[1]>>7;
  110.             Offset[2]=Offset1[2]>>7;
  111.     #ifndef NON_INT
  112.         }
  113.     #endif
  114.     return;
  115. }
  116.  
  117. void main(int argc,char **argv)
  118. {
  119.     int i,w;
  120.     
  121.     if(argc!=1){
  122.         for(i=0;argv[1][i]!='\0';i++){
  123.             Space[0].obj_no*=10;
  124.             if(argv[1][i]<'0' || argv[1][i]>'9'){
  125.                 printf("パラメータエラーです.\n");
  126.                 return;
  127.             }
  128.             Space[0].obj_no+=(int)(argv[1][i]-'0');
  129.         }
  130.     }
  131.     Step=2;
  132.     
  133.     if(Step==0){
  134.         printf("パラメータエラーです.\n");
  135.         return;
  136.     }
  137.     
  138.     printf("Step=%d\n",Step);
  139.     
  140.     printf("画面初期化.\n");
  141.     
  142.     EGB_init(Gwork,1536);
  143.     
  144.     EGB_resolution(Gwork,0,5);
  145.     // EGB_resolution(Gwork,1,6);
  146.     
  147.     EGB_writePage(Gwork,0);
  148.     EGB_clearScreen(Gwork);
  149.     EGB_displayStart(Gwork,0,64,0);
  150.     EGB_displayStart(Gwork,1,0,0);
  151.     EGB_displayStart(Gwork,2,2,2);
  152.     EGB_displayStart(Gwork,3,256,256);
  153.     
  154.     EGB_writePage(Gwork,1);
  155.     EGB_clearScreen(Gwork);
  156.     // EGB_displayStart(Gwork,0,64,0);
  157.     // EGB_displayStart(Gwork,1,0,0);
  158.     // EGB_displayStart(Gwork,2,2,2);
  159.     // EGB_displayStart(Gwork,3,256,256);
  160.     
  161.     EGB_displayPage(Gwork,1,3);
  162.     
  163.     EGB_writePage(Gwork,0);
  164.     
  165.     // SPR_init();
  166.     
  167.     #ifndef NON_INT
  168.         i=VSYNC_set(VSYNC_handler);
  169.         if(i!=0){
  170.             printf("割り込みの登録に失敗しました.\n");
  171.             return;
  172.         }
  173.     #endif
  174.     for(;;){
  175.         #ifdef NON_INT
  176.             #ifndef VSYNC_OFF
  177.                 wait_VSYNC();
  178.             #endif
  179.             VSYNC_handler();
  180.         #endif
  181.         if(End_code==1)break;
  182.         if(Draw_end!=2)continue;
  183.         Draw_end=0;
  184.         clear_screen(W_page,6);
  185.         #ifndef STAR_OFF
  186.             star(Angle,W_page);
  187.         #endif
  188.         wirespace(Angle,Offset,OBJ_NUM,W_page);
  189.         Draw_end=1;
  190.     }
  191.     #ifndef NON_INT
  192.         VSYNC_end();
  193.     #endif
  194.     printf("正常終了.\n");
  195.     // EGB_init(Gwork,1536);
  196. }
  197.  
  198.